﻿Imports System.IO
Imports System.Data.SqlClient

Public Class viewitem
    Public MainForm As Form1
    Public ServerFile As FileInfo
    Public Upid As String
    Private Sub viewitem_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Try
            If ServerFile.Extension = ".pdf" Then
                PictureBox1.Image = My.Resources.pdf
            End If
        Catch ex As Exception
        End Try
    End Sub

    Private Sub PictureBox1_Click(sender As Object, e As EventArgs) Handles PictureBox1.Click
       
    End Sub

    Private Sub Label2_Click(sender As Object, e As EventArgs) Handles Label2.Click
        Dim a
        a = MsgBox("Do you want to permanently remove '" & lbltitle.Text & "'?", MsgBoxStyle.YesNo, "Delete")
        If a = vbYes Then
            Dim con As New SqlConnection
            con.ConnectionString = MainForm.settingsdialog.txtconstr.Text
            Dim sqlcommand As String = "DELETE FROM [DocumentManagement].[dbo].[records] WHERE upid = '" & Upid & "'"
            Dim cmd As New SqlCommand(sqlcommand, con)
            Try
                con.Open()
                cmd.ExecuteNonQuery()
                Try
                    File.Delete(ServerFile.FullName)
                Catch ex As Exception
                End Try
                Me.Dispose()
            Catch ex As Exception
                MsgBox(ex.Message)
            End Try
            con.Close()
        End If
    End Sub
    Dim rowClicked As Integer
    Private Sub PictureBox1_MouseClick(sender As Object, e As MouseEventArgs) Handles PictureBox1.MouseClick
        If e.Button = Windows.Forms.MouseButtons.Left Or e.Button = Windows.Forms.MouseButtons.Right Then
            'rowClicked = DataGridView1.HitTest(e.Location.X, e.Location.Y).RowIndex
            ContextMenuStrip1.Show(PictureBox1, e.Location)
        End If
    End Sub

    Private Sub OpenToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles OpenToolStripMenuItem.Click
        Try
            Process.Start(ServerFile.FullName)
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
    End Sub

    Private Sub SaveToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles SaveToolStripMenuItem.Click
        Try
            Dim save As New SaveFileDialog
            save.Filter = "PDF Files (*.pdf) |*.pdf"
            save.FilterIndex = 2
            save.RestoreDirectory = True
            If save.ShowDialog() = DialogResult.OK Then
                File.Copy(ServerFile.FullName, save.FileName, True)
            End If
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
    End Sub
End Class
